/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package library;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author user
 */
public class DbKoneksi {
    
    Connection conn = null;
    
    public DbKoneksi(){
        try {
            String URL = "jdbc:mysql://localhost:3306/integrasi";
            String USER = "root";
            String PASS = "";
            
            Class.forName("com.mysql.jdbc.Driver");
            this.conn = DriverManager.getConnection(URL, USER, PASS);
            System.out.print("sukses");
        } catch (SQLException ex) {
            Logger.getLogger(DbKoneksi.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DbKoneksi.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    //method untuk mengambil koneksi
    public Connection getConnection(){
        return this.conn;
    }

    //method untuk menutup koneksi
    public void closeConnection(){
        if(this.conn != null){
            try {
                this.conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(DbKoneksi.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
